﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using DAO;
using DTO;
namespace Banking.Member
{
    public partial class ThongTinCaNhan_KhachHang : UserControl
    {
        private KhachHang khachHang;

        public ThongTinCaNhan_KhachHang()
        {
            InitializeComponent();
        }

        public void init(int maKH)
        {
            List<LoaiKH> lstLoaiKH = LoaiKHDA.GetALl(0);
            cbbLoaiKhachHang.DataSource = lstLoaiKH;
            cbbLoaiKhachHang.DisplayMember = "TenLoai";
            cbbLoaiKhachHang.ValueMember = "MaLoai";

            List<TruSo> lstLoaiTruSo = TruSoDA.GetALl(0);
            cbbNganHang.DataSource = lstLoaiTruSo;
            cbbNganHang.DisplayMember = "Ten";
            cbbNganHang.ValueMember = "MaTruSo";

            khachHang = KhachHangDA.GetById(maKH);
            BuildBinding();
        }

        private void BuildBinding()
        {
            if (khachHang != null)
            {
                txtHoTen.DataBindings.Add("Text", khachHang, "Ten");
                txtCMND.DataBindings.Add("Text", khachHang, "CMND");
                txtDiaChi.DataBindings.Add("Text", khachHang, "DiaChi");
                dateNgaySinh.DataBindings.Add("Value", khachHang, "NgaySinh");
                txtDienThoai.DataBindings.Add("Text", khachHang, "SoDT");
                txtPassPost.DataBindings.Add("Text", khachHang, "PassPost");
                cbbNganHang.DataBindings.Add("SelectedValue", khachHang, "MaTruSo");
                cbbLoaiKhachHang.DataBindings.Add("SelectedValue", khachHang, "MaLoaiKH");
                txtGiayPhepKD.DataBindings.Add("Text", khachHang, "GiayPhepKinhDoanh");
                txtNguoiDaiDien.DataBindings.Add("Text", khachHang, "NguoiDaiDien");
                txtMaSoThue.DataBindings.Add("Text", khachHang, "MaSoThue");
            }
            //cbbLoaiKhachHang.SelectedValue = khachHang.MaLoaiKH;

            //cbbNganHang.SelectedValue = khachHang.MaTruSo;

        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            if (txtHoTen.Text == "" || txtCMND.Text == "" || txtPassPost.Text == "")
            {
                MessageBox.Show("Bạn phải cung cấp họ tên ,cmnd , passpost");
                return;
            }

            khachHang.Ten = txtHoTen.Text;
            khachHang.CMND = Convert.ToInt32(txtCMND.Text);
            khachHang.PassPost = Convert.ToString(txtPassPost.Text);
            khachHang.DiaChi = txtDiaChi.Text;
            khachHang.NgaySinh = Convert.ToDateTime(dateNgaySinh.Text);
            khachHang.MaSoThue = Convert.ToInt32(txtMaSoThue.Text);
            khachHang.GiayPhepKinhDoanh = txtGiayPhepKD.Text;
            khachHang.NguoiDaiDien = txtNguoiDaiDien.Text;
            khachHang.SoDT = txtDienThoai.Text;
            KhachHangDA.Update(khachHang);
            MessageBox.Show("Cập nhật thông tin thành công ", "BankingSystem", MessageBoxButtons.OK, MessageBoxIcon.Question);
               
            
        }


       
    }
}
